<?php
/**
 * Created by PhpStorm.
 * User: ZhuMing
 * Date: 2020/1/4
 * Time: 12:09
 */

namespace app\home\controller;

use app\common\model\AfficheModel;
use app\common\model\AfficheTypeModel;
use think\Lang;

/**
 * 公告类
 */
class Sellernews extends BaseSeller
{
    public function _initialize() {
        parent::_initialize();
        Lang::load(APP_PATH . 'home/lang/'.config('default_lang').'/sellermember.lang.php');
    }

      public function index()
    {

 /* 设置卖家当前菜单 */
 $this->setSellerCurMenu('sellernews');
 /* 设置卖家当前栏目 */
 $this->setSellerCurItem('index');

 $affiche = model('afficheModel');
 $condition = array();

 $member = $_SESSION['home']['member_id'];

 $title = input('param.title', '');

 $type_id = input('param.type_id', '');
 if (!empty($title)) {
     $condition['af.title'] = $title;
 }
 if (!empty($type_id)) {
     $condition['af.typeid'] = intval($type_id);
 }

 $store_seller_type = session("store_seller_type");
if($store_seller_type==1){
    $condition['typeid'] = 3;
}else if($store_seller_type==2){
    $condition['typeid'] = 4;
}



 $list = $affiche ->getAfficheListHome($condition, 7,$member);
 
 $afficheType = model('afficheTypeModel');
 $typeList = $afficheType->getAfficheTypeList();
 $this->assign('list', $list);

 

 $this->assign('type_list', $typeList);
 $this->assign('title', $title);
 $this->assign('type_id', $type_id);
 $this->assign('show_page', $affiche->page_info->render());

      return $this->fetch($this->template_dir.'/index');


    }

    public function detail()
    {
        $afficheContent = model('afficheModel');

        $affiche_info =  $afficheContent->where('affiche_id',input("id"))->find();
        $this->assign('affiche_info', $affiche_info);

      
        $member = $_SESSION['home']['member_id'];

        //如果没有读取，设置成已读
        $read = db('affiche_reads')->where(['member_id'=>$member ,'affiche_id'=>input("id") ])->find();

        if(!$read){
            db('affiche_reads')->insert(['affiche_id'=>input("id"),'member_id'=>$member]);
        }
 
        return $this->fetch($this->template_dir . 'detail');
    }


 /**
     *    栏目菜单
     */
    function getSellerItemList() {
      $menu_array[] = array(
          'name' => 'index',
          'text' => lang('index'),
          'url' => url('Sellernews/index'),
      );

      if (request()->action() === 'account_add') {
          $menu_array[] = array(
              'name' => 'account_add',
              'text' => lang('add_account'),
              'url' => url('Selleraccount/account_add'),
          );
      }
      if (request()->action() === 'group_edit') {
          $menu_array[] = array(
              'name' => 'account_edit',
              'text' => lang('edit_account'),
              'url' => 'javascript:void(0)',
          );
      }

      return $menu_array;
  }
}
